﻿layui.config({
    base : '../../js/'
});

layui.use(['jquery','carousel','flow','layer','laypage'], function () {
    var $ = layui.jquery;
    var flow = layui.flow;
    var layer = layui.layer;
    var laypage = layui.laypage;

    SearchArticleList(laypage);
    var width = width || window.innerWeight || document.documentElement.clientWidth || document.body.clientWidth;
    width = width>1200 ? 1170 : (width > 992 ? 962 : width);
    var carousel = layui.carousel;
    //建造实例
    carousel.render({
      elem: '#carousel'
      ,width: width+'px' //设置容器宽度
      ,height:'360px'
      ,indicator: 'inside'
      ,arrow: 'always' //始终显示箭头
      ,anim: 'default' //切换动画方式
      
    });

    $(".home-tips-container span").click(function(){
        layer.msg($(this).text(), {
            time: 20000, //20s后自动关闭
            btn: ['明白了']
        });
    });


    $(".recent-list .hotusers-list-item").mouseover(function () {
        var name = $(this).children(".remark-user-avator").attr("data-name");
        var str = "【"+name+"】的评论";
        layer.tips(str, this, {
            tips: [2,'#666666']
        });
    });


    $("#QQjl").mouseover(function(){
        layer.tips('QQ交流', this,{
            tips: 1
        });
    });
    $("#gwxx").mouseover(function(){
        layer.tips('给我写信', this,{
            tips: 1
        });
    });
    $("#xlwb").mouseover(function(){
        layer.tips('新浪微博', this,{
            tips: 1
        });
    });
    $("#htgl").mouseover(function(){
        layer.tips('后台管理', this,{
            tips: 1
        });
    });
    
    $(function () {

        $(".fa-home").parent().parent().addClass("layui-this");
        //播放公告
        playAnnouncement(5000);
    });
    
    function playAnnouncement(interval) {
        var index = 0;
        var $announcement = $('.home-tips-container>span');
        //自动轮换
        setInterval(function () {
            index++;    //下标更新
            if (index >= $announcement.length) {
                index = 0;
            }
            $announcement.eq(index).stop(true, true).fadeIn().siblings('span').fadeOut();  //下标对应的图片显示，同辈元素隐藏
        }, interval);
    }
});

function classifyList(id){
    	layer.msg('功能要自己写');
}
function SearchArticleList(laypage) {
    var index = layer.load(0, {
        shade: false,
        offset: ['100px']
    }); //0代表加载的风格，支持0-2
    var keyword=$("#inputkey").val();
    // var data1 = {
    //     page: pg,
    //     size: sz,
    //     type:id,
    //     keyword:keyword
    // }


    $.ajax({
        url: '/SearchArticleList',
        type: 'post', //GET
        async: true, //或false,是否异步
        dataType: 'json',
        contentType: 'application/json',
        success: function(data) {
            layer.close(index);
            console.log(data);
            console.log(data.Type);
            console.log("sfasfafaffaf");
            if(data.Type == 1) {
                console.log(data);
                console.log(data.Type);
                // if(type == 1) {
                    laypage.render({
                        elem: 'page',
                        count: data.Count,
                        layout: ['prev', 'page', 'next', 'count'],
                        jump: function(obj, first) {
                            if(!first) {
                                SearchArticleList(0, obj.curr, obj.limit);
                            }
                        }
                    });
                // }
                $("#parentArticleList").html("");
                $.each(data.data ,function(index, item) {
                    console.log(item.Articleoutline)
                    var lihtml = '';
                    lihtml += '<div class="article shadow animated zoomIn">';
                    lihtml += '<div class="article-left ">';
                    lihtml += '<img src="img/jzytp.JPG" alt="Tomcat优化性能，JVM优化">';
                    lihtml += '</div>';
                    lihtml += '<div class="article-right">';
                    lihtml += '<div class="article-title">';
                    lihtml += '<span class="article_is_top">置顶</span>&nbsp;<span class="article_is_yc">原创</span>&nbsp;';
                    lihtml += '<a href="detail.html">Tomcat优化性能，JVM优化</a>';
                    lihtml += '</div>';
                    lihtml += '<div class="article-abstract">';
                    lihtml += ''+item.Articleoutline;
                    lihtml += '</div>';
                    lihtml += '</div>';
                    lihtml += '<div class="clear"></div>';
                    lihtml += '<div class="article-footer">';
                    lihtml += '<span><i class="fa fa-clock-o"></i>&nbsp;&nbsp;2018-07-27 09:34:33</span>';
                    lihtml += '<span class="article-author"><i class="fa fa-user"></i>&nbsp;&nbsp; 听雨·湘潭</span>';
                    lihtml += '<span><i class="fa fa-tag"></i>&nbsp;&nbsp;<a href="javascript:classifyList(10);"> Tomcat</a></span>';
                    lihtml += '<span class="article-viewinfo"><i class="fa fa-eye"></i>&nbsp;286</span>';
                    lihtml += '<span class="article-viewinfo"><i class="fa fa-commenting"></i>&nbsp;3</span>';
                    lihtml += '</div>';
                    lihtml += '</div>';
                    $("#parentArticleList").append(lihtml);
                });

            }
        }

    });

}



